var deviceone = require("deviceone");
var cacher = deviceone.sm("do_DataCache");
var nf = deviceone.sm("do_Notification");
var common = require("common");
var imgMax = 3;

module.exports.type = {
	/** community * */
	COMMUNIty : 1,
	/** CIRCLE * */
	CIRCLE : 2,
};

/**
 * ';'分隔图片字符串,转变成[{source:imgs[j],imgCount:""}]格式
 * 
 * @isShowAll:是否显示图片总数量，imgCount:共x张
 * @imgStr:img';'分隔图片字符串
 * @callback:回调函数
 */
var imgFormatFun = function(isShowAll, imgStr) {
	if (null == imgStr || '' == imgStr) {
		return null;
	}
	var imgs = imgStr.split(";");
	if (imgs.length <= 0) {
		return null;
	}
	// 图片的数据
	var jsonImgs = [];
	var imgsL = imgs.length;
	var showCount = "";
	if (imgsL > imgMax && isShowAll) {
		showCount = "共" + imgsL + "张";
		imgsL = imgMax;
	}
	// 图片的数据
	for (var j = 0; j < imgsL; j++) {
		if (j == (imgsL - 1) && isShowAll) {//列表最后才显示共多少张
			jsonImgs.push({
				source : imgs[j],
				imgCount : showCount
			});
		} else {
			jsonImgs.push({
				source : imgs[j],
				imgCount : ""
			});
			
		}
	}
	return jsonImgs;
}
module.exports.fun = {
	img : {
		format : imgFormatFun
	}
};

module.exports.imgMax = imgMax;
